<!DOCTYPE html>
<html>
<head>
	<title>NewReport</title>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
	<link rel="stylesheet" href="__ROOT__/public/static/layui/css/layui.css" media="all">
	<script src="__ROOT__/public/static/layui/layui.js" charset="utf-8"></script> 
  <script type="text/javascript" src="__ROOT__/public/static/jquery-3.4.1.min.js"></script> 
  <script  src="__ROOT__/public/static/highchart/code/highcharts.js"></script>
 
 <script type="text/javascript">
    var stepflags=["{$step1}","{$step2}","{$step3}","{$step4}","{$step5}","{$step6}"];
    var cols=[];
    cols[0]={checkbox:true,fixed:true};
    cols[1]={field:'顺序',title:'顺序',align:'center',width:70,sort:true};
    cols[2]={field:'学号',title:'学号',edit:'text',align:'center',width:140};
    cols[3]={field:'姓名',title:'姓名',edit:'text',align:'center',width:100};
    cols[4]={field:'平时',title:'平时',edit:'text',align:'center',width:60};
    cols[5]={field:'期末',title:'期末',edit:'text',align:'center',width:60};
    cols[6]={field:'总评',title:'总评',align:'center',width:60}; 
    var stheadercols=formstheadercols({$stheadercols_array});
    var needreloadtable4=false;
    function formstheadercols(arr) {
      var t=[];
      for (var i = 0; i < 7; i++) {
        t.push(cols[i]);
      }
      for (var i = 0; i < arr.length; i++) {
        t.push(arr[i]);
      }
      return t;
    }
    function showstatus(i) {
      var t=document.getElementById('step'+i+'img');
      if (stepflags[i-1]=="Y") {
        t.setAttribute('src','__ROOT__/public/img/duigou.png');
      } else {
        t.setAttribute('src','__ROOT__/public/img/ing.png');
      }
    }
    function setstatustoright(i) {
      var t=document.getElementById('step'+i+'img');
      (stepflags[i-1]="Y");
      t.setAttribute('src','__ROOT__/public/img/duigou.png'); 
    }
    function setstatustoing(i) {
      var t=document.getElementById('step'+i+'img');
      (stepflags[i-1]="X");
      t.setAttribute('src','__ROOT__/public/img/ing.png'); 
    }
  </script>
</head>
<body  class="layui-layout-body">
	<div class="layui-layout layui-layout-admin">
		<div class="layui-header">
			<ul class="layui-nav" lay-filter="header">
				<li class="layui-nav-item"><a href="firstPageInfo">首页信息</a></li>
				<li class="layui-nav-item layui-this" ><a href="mypapers">试卷分析列表</a></li>
				<li class="layui-nav-item" ><a href="myinfo">我的信息</a></li> 
				<li class="layui-nav-item  layui-layout-right" >____工号:{$gh}____</li> 
			</ul>
		</div>
		<div class="layui-side layui-bg-black">
			<div class="layui-side-scroll">
				<div class="layui-side-scroll"> 
					<ul class="layui-nav layui-nav-tree"  lay-filter="test">
						<li class="layui-nav-item" onclick="showdiv(1)"><a href="javascript:;">1.设置基本信息<img id="step1img" style="width: 16px;height: 16px" src=""></a></li>
						<li class="layui-nav-item" onclick="showdiv(2)"><a href="javascript:;">2.设置权重<img id="step2img" style="width: 16px;height: 16px" src=""></a></li>
						<li class="layui-nav-item" onclick="showdiv(3)"><a href="javascript:;">3.导入学生名单<img id="step3img" style="width: 16px;height: 16px" src=""></a></li>
						<li class="layui-nav-item" onclick="showdiv(4)"><a href="javascript:;">4.录入成绩<img id="step4img" style="width: 16px;height: 16px" src=""></a></li>
						<li class="layui-nav-item" onclick="showdiv(5)"><a href="javascript:;">5.加入分析评语<img id="step5img" style="width: 16px;height: 16px" src=""></a></li>
						<li class="layui-nav-item" onclick="showdiv(6)"><a href="javascript:;">6.生成分析报表<img id="step6img" style="width: 16px;height: 16px" src=""></a></li>
					</ul>
				</div>
			</div>
		</div>

  <script>
    for (var i = 1; i <=stepflags.length; i++) {
      showstatus(i);
    }
  </script>
<script type="text/javascript">
  layui.use(['layer','element'], function(){
  var element = layui.element; //导航的hover效果、二级菜单等功能，需要依赖element模块
  //监听导航点击
  element.on('nav(header)', function(elem){
    // console.log(elem)
    // layer.msg(elem.text());
  });
});
  function showdiv(x) {
   console.log(x);
   var t=document.getElementById('div0');
   t.setAttribute("style","display:none");
   if (x==5&&stepflags[0]=='Y'&&stepflags[1]=='Y'&&stepflags[2]=='Y'&&stepflags[3]=='Y') {
    drawObjByAjax();
   }
   for (var i = 1; i < 7; i++) {
    if(i==x){
     t=document.getElementById('div'+x);
     t.setAttribute("style","display");
   }
   else{
     t=document.getElementById('div'+i);
     t.setAttribute("style","display:none");
   }
 }
}
</script>



		<div class="layui-body">
			<!-- 内容主体区域 -->
			<div style="padding: 15px;">
				<div id="div0">
					<h1 style="color: red">请依次按左侧顺序操作。</h1>
				</div>
        <div>
          <h5 style="color: red" id="currentpaper" >当前试卷：{$currentpapername}</h5>
        </div>
        <div id="div1" style="display: none; ">
         <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
          <legend>试卷基本信息</legend>
        </fieldset>
        <form class="layui-form" action="" lay-filter="baseinfo">
          <div class="layui-form-item">
            <div class="layui-inline" >
            <label class="layui-form-label">试卷名称</label>
            <div class="layui-input-block" style="width: 420px">
              <input type="text" name="papaername" value="{$papaername}" lay-verify="papaername" autocomplete="off" placeholder="请输入试卷名称" class="layui-input">
            </div>
            </div>
            <div class="layui-inline">
              <font color="red">*</font>须以(20XX-20XX)-Y-{$gh}-开头
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">所在专业</label>
            <div class="layui-input-block">
              <input type="text" name="major" lay-verify="major" autocomplete="off" placeholder="请输入所在专业名称" class="layui-input" value="{$major}">
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">课程名称</label>
            <div class="layui-input-block">
              <input type="text" name="coursename" lay-verify="coursename" autocomplete="off" placeholder="请输入课程名称" class="layui-input" value="{$coursename}">
            </div>
          </div>
          <div class="layui-form-item">
           <div class="layui-inline">
            <label class="layui-form-label">考试日期</label>
            <div class="layui-input-block">
              <input type="text" name="examdate" value="{$examdate}" id="examdate" autocomplete="off" class="layui-input">
            </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label">考试对象</label>
            <div class="layui-input-block">
              <input type="text" name="stclass" lay-verify="stclass" autocomplete="off" placeholder="请输入课程考核对象" class="layui-input" value="{$stclass}">
            </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label">考核方式</label>
            <div class="layui-input-block">
             <select id="exammodel" name="exammodel" lay-filter="exammodel">
              <option value="0">考试</option>
              <option value="1">考查</option>
            </select>
          </div>
        </div>
      </div>
      <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">培养目标1</label>
        <div class="layui-input-block">
          <textarea placeholder="请输入课程培养目标1" lay-verify="classobject1"  class="layui-textarea" name="classobject1">{$classobject1}</textarea>
        </div>
      </div>
      <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">培养目标2</label>
        <div class="layui-input-block">
          <textarea placeholder="请输入课程培养目标2" lay-verify="classobject2"  class="layui-textarea" name="classobject2">{$classobject2}</textarea>
        </div>
      </div>
      <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">培养目标3</label>
        <div class="layui-input-block">
          <textarea placeholder="请输入课程培养目标3" lay-verify="classobject3"  class="layui-textarea" name="classobject3">{$classobject3}</textarea>
        </div>
      </div>


      <div class="layui-form-item">
        <div class="layui-input-block">
          <button type="button" class="layui-btn layui-btn-normal" id="baseinfo-form-setval">重置</button>
          <button type="submit" class="layui-btn" lay-submit="" lay-filter="baseinfosubmit">提交</button>
        </div>
      </div>
    </form>
  </div>

<script type="text/javascript">
  document.getElementById('exammodel').value={$exammodel};
//基本信息
  layui.use(['form','layer','laydate'], function(){
      var form = layui.form,layer = layui.layer,laydate = layui.laydate;
      //日期
      laydate.render({
        elem: '#examdate'
      });

      //自定义验证规则
      form.verify({
        papaername:[/^\(20\d{2}-20\d{2}\)-[123]-{$gh}-.+/,'须以(20XX-20XX)-1-或(20XX-20XX)-2-或(20XX-20XX)-3-开头，1,2表示第一、二学期，3表示短学期,后接工号和课程名，以-号隔开，注意使用英文的小括号'],
        major:[/^.{1,}$/,'专业名称必填'],
        coursename:[/^.{1,}$/,'课程名称必填'],
        stclass:[/^.{1,}$/,'考试对象必填'],
        classobject1:[/^.{1,}$/,'教学目标1必填'],
        classobject2:[/^.{1,}$/,'教学目标2必填'],
        classobject3:[/^.{1,}$/,'教学目标3必填']
      });

      //监听提交
      form.on('submit(baseinfosubmit)', function(data){ 
        jQuery.ajax({
            type:"POST",
            contentType:"application/json;charset=UTF-8",
            url:"{$baseurl}/index.php/index/index/step1data",
            data:JSON.stringify(data.field),
            beforeSend:function(){
              layer.msg('正在上传......');
            },
            success:function (result) {
              var x=JSON.parse(result);
              if (x.result==1) {
                setstatustoright(1);
                document.getElementById('currentpaper').innerHTML='当前试卷：'+data.field.papaername;
                layer.msg(x.info);
              }else{
                setstatustoing(1);
                layer.msg(x.info);
              }
            }
          });
        return false;
      });

      //表单赋值
      layui.$('#baseinfo-form-setval').on('click', function(){
        setstatustoing(1);
        form.val('baseinfo', {
          "papaername": "{$papaername}",
          "major":"{$major}",
          "coursename":"{$coursename}",
          "examdate":"{$examdate}",
          "exammodel":"{$exammodel}",
          "stclass":"{$stclass}",
          "classobject1":"{$classobject1}",
          "classobject2":"{$classobject2}",
          "classobject3":"{$classobject3}"
        });
      }); 
    }); 
</script>

 


<div id="div2"  style="display: none;">
 <form class="layui-form" action="" lay-filter="weightinfo">
 <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
  <legend>1.设置权重</legend>
</fieldset>


  <div class="layui-form-item">
    <div class="layui-inline">
      <label class="layui-form-label">成绩构成</label>
    </div>
    <div class="layui-inline">
      <label class="layui-form-label">平时百分比</label>
      <div class="layui-input-block">
        <input type="text" name="pscj" value="{$pscj}" id="pscj" lay-verify="pscj" autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-inline">
      <label  class="layui-form-label">期末百分比</label>
      <div class="layui-input-block">
        <input type="text" name="qmcj" value="{$qmcj}" id="qmcj" lay-verify="qmcj" autocomplete="off" class="layui-input">
      </div>
    </div>

  </div>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
  <legend>2.其中平时成绩中各目标模块权重</legend>
</fieldset>


  <div class="layui-form-item">
    <div class="layui-inline">
      <label class="layui-form-label">平时构成</label>
    </div>
    <div class="layui-inline">
      <label class="layui-form-label">目标1百分比</label>
      <div class="layui-input-block">
        <input type="text" name="psobj1" value="{$psobj1}" id="psobj1" lay-verify="psobj1" autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-inline">
      <label  class="layui-form-label">目标2百分比</label>
      <div class="layui-input-block">
        <input type="text" name="psobj2" value="{$psobj2}" id="psobj2" lay-verify="psobj2" autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-inline">
      <label  class="layui-form-label">目标3百分比</label>
      <div class="layui-input-block">
        <input type="text" name="psobj3" value="{$psobj3}" id="psobj3" lay-verify="psobj3" autocomplete="off" class="layui-input">
      </div>
    </div>

  </div>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
  <legend>3.期末试卷模块<font color="red">(模块以1,2,...,标号，模块分、权重请填整百分数，各和为100)</font></legend>
</fieldset>

<script type="text/html" id="weighttabletoolbar">
  <a class="layui-btn layui-btn-xs" lay-event="del">删除</a>
</script>

<div >
  <table id="weightdata" class="layui-table"  lay-filter="weightdata">
  </table>
</div> 
<div class="layui-input-block">
  <button type="button" class="layui-btn layui-btn-normal" id="addnewline">加一行</button>
</div>

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
  <legend>4.确认并上传数据</legend>
</fieldset>
<div class="layui-inline">
  <div class="layui-input-block">
    <button type="submit" class="layui-btn"  lay-submit="" lay-filter="weightinfosubmit" id="dataconfirm">确认并上传，若有修改再次点上传，最后一次为准</button>
  </div>
</div>

</form>
</div>
<script>  
  layui.use(['form','layer','table'],function(){
    var form = layui.form,layer = layui.layer;
    var table=layui.table;
    // var selectline;
    table.render({
        elem:'#weightdata',
        url:"getweightdata",
        method:'get',
        page:false,
        cols:[[{checkbox:true,fixed:true}, 
        {field:'tid',title:'题(模块)号',edit:'text',align:'center',width:120,sort:true},
        {field:'modulepoint',title:'模块分值',edit:'text',width:160},
        {field:'obj1',title:'目标1权重',edit:'text',width:160},
        {field:'obj2',title:'目标2权重',edit:'text',width:160},
        {field:'obj3',title:'目标3权重',edit:'text',width:160},
        {fixed:'right',title:'操作',width:100,align:'center',toolbar:'#weighttabletoolbar'}
        ]],
        id:'weightdatatablereload',
        parseData:function(res) {
          // console.log(res);
          var t=JSON.parse(res); 
          return {
            "code":0,
            "msg":"good",
            "count":t.count,
            "data":t.data
          }
        },
        done:function (res,curr,count) {
         $(document).on('keydown','.layui-table-edit',function(e){
          var td=$(this).parent('td'),
              tr=td.parent('tr'),
              trs=tr.parent().parent().find("tr"),
              tr_index=tr.index(),
              td_index=td.index(),
              td_last_index=tr.find('[data-edit="text"]:last').index(),
              td_first_index=tr.find('[data-edit="text"]:first').index();
          switch(e.keyCode){
            case 39://向右
                td.nextAll('[data-edit="text"]:first').click();
                if (td_index==td_last_index) {
                  tr.next().find('td').eq(td_first_index).click();
                  if (tr_index==trs.length-1) {
                    trs.eq(0).find('td').eq(td_first_index).click();
                  }
                }
                setTimeout(function(){$('.layui-table-edit').select()},0);
                break;
            case 37://向左
                td.prevAll('[data-edit="text"]:first').click();
                setTimeout(function(){$('.layui-table-edit').select()},0);
                break;
            case 38://向上
                tr.prev().find('td').eq(td_index).click();
                setTimeout(function(){$('.layui-table-edit').select()},0);
                break;
            case 13://回车
            case 40://向下
                tr.next().find('td').eq(td_index).click();
                setTimeout(function(){$('.layui-table-edit').select()},0);
                break;
          }
        });
      } 
      }); 
      table.on('tool(weightdata)',function (obj) {
        var data=obj.data;  
        if(obj.event === 'del'){
          layer.confirm('真的删除行么', function(index){
            obj.del();  
            jQuery.ajax({
                type:"POST",
                contentType:"application/json;charset=UTF-8",
                url:"{$baseurl}/index.php/index/index/deleteweightlinebypaperidandid/id/"+data.id, 
                beforeSend:function(){
                  layer.msg('正与服务器联系......');
                },
                success:function (result) {
                  var x=JSON.parse(result);
                  if (x.result==1) { 
                    setstatustoing(2);
                    layer.msg('删行成功！');
                  }else{
                    layer.msg('删行失败！');
                  }
                }
              });
          });
        }
      });
      table.on('checkbox(weightdata)',function (obj) {
          // selectline=obj.tr;
          // selectline.insertBefore(selectline.prev());
      });
      table.on('edit(weightdata)',function (obj) {
        var value=obj.value,data=obj.data,field=obj.field;
        // layer.msg('[ID: '+ data.id +'] ' + field + ' 字段更改为：'+ value);  
        jQuery.ajax({
            type:"POST",
            contentType:"application/json;charset=UTF-8",
            url:"{$baseurl}/index.php/index/index/updateOneFieldbypaperidandid/id/"+data.id+"/fieldname/"+field+"/fieldvalue/"+value, 
            beforeSend:function(){
              // layer.msg('正与服务器联系......');
            },
            success:function (result) {
              var x=JSON.parse(result);
              if (x.result==1) { 
                setstatustoing(2);
              }else{
                layer.msg('更新失败！');
              }
            }
          });

      });
      //加一行
      layui.$('#addnewline').on('click', function(){
        jQuery.ajax({
            type:"POST",
            contentType:"application/json;charset=UTF-8",
            url:"{$baseurl}/index.php/index/index/addnewweightline",
            // data:JSON.stringify(data.field),
            beforeSend:function(){
              layer.msg('正与服务器联系......');
            },
            success:function (result) {
              var x=JSON.parse(result);
              if (x.result==1) {
                table.reload('weightdatatablereload');
                setstatustoing(2);
                layer.msg('加行成功！');
              }else{
                layer.msg('加行失败！');
              }
            }
          });
        // var tempdata=table.cache["weightdatatablereload"];
        // var templinedata={"tid":5,"obj1":0,"obj2":0,"obj3":0,"LAY_TABLE_INDEX":2};
        // table.cache["weightdatatablereload"].push(templinedata);
        // table.reload('weightdata',{data:tempdata});
        // layer.msg(JSON.stringify(tempdata));
      });  
  //权重信息
 
      //自定义验证规则
      form.verify({
        pscj:function (data,item) {  
          var k=new RegExp(/^\d{1,2}$/);
          if (!k.test(data)) { 
            setstatustoing(2);
            return "平时占比必须要1-2位数字";
          } 
          var t1=parseInt(document.getElementById('pscj').value);
          var t2=parseInt(document.getElementById('qmcj').value);
          if (t1+t2!=100) {
            setstatustoing(2);
            return "平时与期末占比和必须为100";
          }
        },
        qmcj:function (data,item) {
          var k=new RegExp(/^\d{1,2}$/);
          if (!k.test(data)) { 
            setstatustoing(2);
            return "期末占比必须要1-2位数字";
          }
        },
        psobj1:function (data,item){
          var k=new RegExp(/^\d{1,2}$/);
          if (!k.test(data)) { 
            setstatustoing(2);
            return "平时成绩中各模块分占比必须要1-2位数字";
          } 
          var t1=parseInt(document.getElementById('psobj1').value);
          var t2=parseInt(document.getElementById('psobj2').value);
          var t3=parseInt(document.getElementById('psobj3').value);
          if (t1+t2+t3!=100) {
            setstatustoing(2);
            return "平时各模块分之和必须为100";
          }
        },
        psobj2:function (data,item){
          var k=new RegExp(/^\d{1,2}$/);
          if (!k.test(data)) { 
            setstatustoing(2);
            return "平时成绩中各模块分占比必须要1-2位数字";
          } 
        },
        psobj3:function (data,item){
          var k=new RegExp(/^\d{1,2}$/);
          if (!k.test(data)) { 
            setstatustoing(2);
            return "平时成绩中各模块分占比必须要1-2位数字";
          } 
        }
      });

      //监听提交
      form.on('submit(weightinfosubmit)', function(data){
        var loc= checktabledataisnotright();
        if (loc>0) {
          setstatustoing(2);
          if (loc==999) {
              layer.msg('各模块分加和不为100!!! 请检查:)');
              return false;
          }
          layer.msg('权重数据表中模块号：'+loc+' 的权重加和不为100!!! 请检查:)');
          return false;
        }
        jQuery.ajax({
            type:"POST",
            contentType:"application/json;charset=UTF-8",
            url:"{$baseurl}/index.php/index/index/step2data",
            data:JSON.stringify(data.field),
            beforeSend:function(){
              layer.msg('正在联系服务器......');
            },
            success:function (result) {
              var x=JSON.parse(result);
              // layer.msg(result); 
              if (x.result==1) {
                setstatustoright(2);
                console.log(stheadercols);
                stheadercols=formstheadercols(eval("("+x.headstr+")"));
                console.log(stheadercols);
                layui.reloadtable4();
                layui.reloadweightresulttable();
                layer.msg(x.info);
              }else{
                layer.msg(x.info);
              }
            }
          });
        return false;
      });
      function checktabledataisnotright() {
        var td=table.cache['weightdatatablereload'];
        var tsum=0;
        for (var i = 0; i < td.length; i++) {
          // console.log(td[i]);
          if (parseInt(td[i].obj1)+parseInt(td[i].obj2)+parseInt(td[i].obj3)!=100) {
            return parseInt(td[i].id);
          }
          tsum=tsum+parseInt(td[i].modulepoint)
        }
        if (tsum!=100) {return 999;}
        return -1;
      }      
    }); 
</script>













<div id="div3"  style="display: none;">
  <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
    <legend>1.上传成绩单以生成名单</legend>
  </fieldset>
  <div class="layui-inline"> 
        <div class="layui-inline-block">
          文件模板:可以先下载excel模板(<font color="red"><a href="__ROOT__/public/filemodel/sample.xls" style="color: #F40" download="sample.xls">点我下载</a></font>)，填好后上传，或采用格式2的成绩单文件。
        </div>
   </div>



  <div class="layui-upload">
    <button type="button" class="layui-btn layui-btn-normal"  id="choosefile">选择Excel文件</button>
    <button type="button" class="layui-btn" id="begintouploadfile">开始上传</button>
  </div>
  <div class="layui-progress" lay-filter="uploadprogress">
    <div class="layui-progress-bar"  lay-percent="0%"></div>
  </div>


  <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
    <legend><font color="red">OR.</font> 手动输入学生人数</legend>
  </fieldset>
  
  <form class="layui-form" action="" lay-filter="studentsinfo">
    <div class="layui-form-item">
      <div class="layui-inline">
        <label class="layui-form-label">学生人数</label>
        <div class="layui-input-block">
          <input type="text" name="stcounts" value="{$stcounts}" id="stcounts" lay-verify="stcounts" autocomplete="off" class="layui-input">
        </div>
      </div>
    </div>
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
    <legend>2.确认学生信息</legend>
  </fieldset>
  <div class="layui-form-item">
      <div class="layui-inline">
         <div class="layui-input-block">
            <button type="submit" class="layui-btn"  lay-submit="" lay-filter="stinfosubmit" id="stdataconfirm">确认</button>
        </div>
     </div>
  </div>
  </form>
</div>
<script>
layui.use(['upload','element','form'],function(){
 var upload=layui.upload;
 var element=layui.element;
 var form=layui.form;
 upload.render({
  elem:'#choosefile',
  url:'treatuploadexcelfile',
  auto:false,
  accept:'file',
  exts:'xls|xlsx',
  multiple:false,
  method:'post',
  bindAction:'#begintouploadfile',
  done:function(res) {
   // var k=JSON.parse(res); 
   var st=document.getElementById('stcounts');
   st.setAttribute('value',res.count);
   setstatustoing(3);
   layer.msg('上传成功');
 },
 progress:function (n) {
   element.progress('uploadprogress',n+'%');
          // console.log(n);
        }
      });
 //自定义验证规则
  form.verify({
        stcounts:function (data,item) {  
          var k=new RegExp(/^\d{1,3}$/);
          if (!k.test(data)) { 
            return "学生数应为1-3位数字";
          }
        }
      });
 form.on('submit(stinfosubmit)', function(data){
  jQuery.ajax({
            type:"POST",
            contentType:"application/json;charset=UTF-8",
            url:"{$baseurl}/index.php/index/index/step3data",
            data:JSON.stringify(data.field),
            beforeSend:function(){
              layer.msg('正在联系服务器......');
            },
            success:function (result) {
              var x=JSON.parse(result);
              if (x.result==1) {
                setstatustoright(3);
                layui.reloadtable4();
                layer.msg(x.info);
              }else{
                setstatustoing(3);
                layer.msg(x.info);
              }
            }
          });
  return false;
 });
});
</script>














<div id="div4"  style="display: none;">
  <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
    <legend>录入卷面模块成绩</legend>
  </fieldset>
  <div style="color: red">为试卷分析，可仅录入平时成绩和各模块成绩数据。</div>
  <div id="datatable">
    <table class="layui-table"  lay-filter="stscoredata" id="stscoredata"></table>
  </div>
  <div class="layui-inline">
   <div class="layui-input-block">
     <div style="margin-top: 50px;margin-left: 60px">
      <button type="button" onclick="confirmstscoresdata()" class="layui-btn">学生成绩录入完成</button>
    </div>
  </div>
</div>
</div>
<script>
  function confirmstscoresdata() {
    jQuery.ajax({
            type:"POST",
            contentType:"application/json;charset=UTF-8",
            url:"{$baseurl}/index.php/index/index/step4data",
            beforeSend:function(){
              layer.msg('正在联系服务器......');
            },
            success:function (result) {
              var x=JSON.parse(result);
              if (x.result==1) {
                setstatustoright(4);
                // draw_obj1();
                drawObjByAjax();
                layer.msg(x.info);
              }else{
                setstatustoing(4);
                layer.msg(x.info);
              }
            }
          });
  }
  
  layui.use(['table','layer'],function(){
    var table=layui.table,layer=layui.layer;
    table.render({
      elem:'#stscoredata',
      url:"getstscoredata",
      method:'get',
      page:false,
      cols:[stheadercols],
      id:'stscoresdatatable',
      parseData:function(res) {  
          var t=JSON.parse(res); 
          return {
            "code":0,
            "msg":"good",
            "count":t.count,
            "data":t.data
          }
        },
      done:function (res,curr,count) {
        this.cols = []; //（关键代码）将cols初始化，否则表格重载时无法正确重新渲染表头
        $(document).on('keydown','.layui-table-edit',function(e){
          var td=$(this).parent('td'),
              tr=td.parent('tr'),
              trs=tr.parent().parent().find("tr"),
              tr_index=tr.index(),
              td_index=td.index(),
              td_last_index=tr.find('[data-edit="text"]:last').index(),
              td_first_index=tr.find('[data-edit="text"]:first').index();
          switch(e.keyCode){
            case 39://向右
                td.nextAll('[data-edit="text"]:first').click();
                if (td_index==td_last_index) {
                  tr.next().find('td').eq(td_first_index).click();
                  if (tr_index==trs.length-1) {
                    trs.eq(0).find('td').eq(td_first_index).click();
                  }
                }
                setTimeout(function(){$('.layui-table-edit').select()},0);
                break;
            case 37://向左
                td.prevAll('[data-edit="text"]:first').click();
                setTimeout(function(){$('.layui-table-edit').select()},0);
                break;
            case 38://向上
                tr.prev().find('td').eq(td_index).click();
                setTimeout(function(){$('.layui-table-edit').select()},0);
                break;
            case 13://回车
            case 40://向下
                tr.next().find('td').eq(td_index).click();
                setTimeout(function(){$('.layui-table-edit').select()},0);
                break;
          }
        });
      }
      });  

    table.on('edit(stscoredata)',function (obj) {
      if (stepflags[1]=='X') {
        layer.msg('您必须先完成第2步权重设置，才能录入成绩');
        return;
      }
      var value=obj.value,data=obj.data,field=obj.field;
      //layer.msg('[ID: '+ data.id +'] ' + field + ' 字段更改为：'+ value); 
      // layer.msg('[顺序: '+ data.顺序 +'] ' + field + ' 字段更改为：'+ value);  
        jQuery.ajax({
          type:"POST",
          contentType:"application/json;charset=UTF-8",
          url:"{$baseurl}/index.php/index/index/updateStscoreOneFieldbypaperidandid/id/"+data.顺序+"/fieldname/"+field+"/fieldvalue/"+value, 
          beforeSend:function(){
              // layer.msg('正与服务器联系......');
            },
            success:function (result) {
              var x=JSON.parse(result);
              if (x.result==1) { 
                setstatustoing(4);
              }else{
                layer.msg('更新失败！');
              }
            }
          });
      });


      layui.define(function (exports) { 
          exports('reloadtable4', function() {
              console.log('reloadtable4');
              console.log(stheadercols);
              table.reload('stscoresdatatable',{cols:[stheadercols]});
            });
        });
        
  });
    </script>


















<div id="div5"  style="display: none;">
  
  <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
    <legend>总体权重与分值汇总</legend>
  </fieldset>
  <div class="layui-input-block" style="align-self: center;">
    <div>
      <table class="layui-table"  lay-filter="weightresulttable" id="weightresulttable"></table>
     </div>
  </div>
   <div class="layui-input-block">
         <div id="avgdiagcontainer" style="border: 1px solid #EEE; width: 900px; height: 300px; margin: 0 auto;border-radius: 5px">
         </div>
      </div>

  <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
    <legend>目标达成情况分析</legend>
  </fieldset>
<form class="layui-form" action="" lay-filter="analysisinfo">       
 
    <div class="layui-form-item layui-form-text">
      <label class="layui-form-label">培养目标1达成情况分析</label>
      <div class="layui-input-block">
         <div id="obj1diagcontainer" style="border: 1px solid #EEE; width: 900px; height: 300px; margin: 0 auto;border-radius: 5px">
         </div>
      </div>
      <div class="layui-input-block">
        <textarea placeholder="关于课程培养目标1的达成情况" class="layui-textarea" lay-verify="obj1descibe"  name="obj1descibe">{$obj1descibe}</textarea>
      </div>
      <div class="layui-input-block">
        <textarea placeholder="关于课程培养目标1的存在问题" class="layui-textarea" lay-verify="obj1pro"  name="obj1pro">{$obj1pro}</textarea>
      </div>
      <div class="layui-input-block">
        <textarea placeholder="关于课程培养目标1的教学改进措施" class="layui-textarea" lay-verify="obj1method"  name="obj1method">{$obj1method}</textarea>
      </div>
    </div>
    <div class="layui-form-item layui-form-text">
      <label class="layui-form-label">培养目标2达成情况分析</label>
      <div class="layui-input-block">
         <div id="obj2diagcontainer" style="border: 1px solid #EEE; width: 900px; height: 300px; margin: 0 auto;border-radius: 5px"></div>
      </div>
      <div class="layui-input-block">
        <textarea placeholder="关于课程培养目标2的达成情况" class="layui-textarea" lay-verify="obj2descibe"  name="obj2descibe">{$obj2descibe}</textarea>
      </div>
      <div class="layui-input-block">
        <textarea placeholder="关于课程培养目标2的存在问题" class="layui-textarea" lay-verify="obj2pro"  name="obj2pro">{$obj2pro}</textarea>
      </div>
      <div class="layui-input-block">
        <textarea placeholder="关于课程培养目标2的教学改进措施" class="layui-textarea" lay-verify="obj2method" name="obj2method">{$obj2method}</textarea>
      </div>
    </div>
    <div class="layui-form-item layui-form-text">
      <label class="layui-form-label">培养目标3达成情况分析</label>
      <div class="layui-input-block">
         <div id="obj3diagcontainer" style="border: 1px solid #EEE; width: 900px; height: 300px; margin: 0 auto;border-radius: 5px"></div>
      </div>

      <div class="layui-input-block">
        <textarea placeholder="关于课程培养目标3的达成情况" class="layui-textarea" lay-verify="obj3descibe"  name="obj3descibe">{$obj3descibe}</textarea>
      </div>
      <div class="layui-input-block">
        <textarea placeholder="关于课程培养目标3的存在问题" class="layui-textarea" lay-verify="obj3pro"  name="obj3pro">{$obj3pro}</textarea>
      </div>
      <div class="layui-input-block">
        <textarea placeholder="关于课程培养目标与3教学改进措施" class="layui-textarea" lay-verify="obj3method"  name="obj3method">{$obj3method}</textarea>
      </div>
    </div>


    <div class="layui-form-item">
      <div class="layui-input-block">
        <button type="button" class="layui-btn layui-btn-normal" id="div5resetval">重置</button>
        <button type="submit" class="layui-btn" lay-submit="" lay-filter="div5submit">提交</button>
      </div>
    </div>
  </form>
</div>
<script type="text/javascript">

  layui.use(['table','layer','form'],function(){
    var table=layui.table,layer=layui.layer,form=layui.form;
    table.render({
      elem:'#weightresulttable',
      url:"getWeightResult",
      method:'get',
      width:840,
      page:false,
      initSort: {
              field: 'mk' //排序字段，对应 cols 设定的各字段名
              ,type: 'asc' //排序方式  asc: 升序、desc: 降序、null: 默认排序
          },
      sort:true,
      cols:[[{field:'mk',title:'模块',align:'center',width:120},
        {field:'fz',title:'分值',align:'center',width:100},
        {field:'obj1weight',title:'目标1权重',align:'center',width:100},
        {field:'obj1fz',title:'目标1分值',align:'center',width:100},
        {field:'obj2weight',title:'目标2权重',align:'center',width:100},
        {field:'obj2fz',title:'目标2分值',align:'center',width:100},
        {field:'obj3weight',title:'目标3权重',align:'center',width:100},
        {field:'obj3fz',title:'目标3分值',align:'center',width:100}]],
      id:'getWeightResult_table',
      parseData:function(res) {  
          var t=JSON.parse(res); 
          return {
            "code":0,
            "msg":"good",
            "count":t.count,
            "data":t.data
          }
        }
      });
      layui.define(function (exports) { 
      exports('reloadweightresulttable', function() {
          table.reload('getWeightResult_table');
        });
    });
     //自定义验证规则
  form.verify({
    obj1descibe:function (data,item) {
      var n=data.length;
      if (n<50) {
        return "字数需要超50";
      }
    },
    obj2descibe:function (data,item) {
      if (data.length<50)
          {return "obj2describe 字数需要超50";}
    },
    obj3descibe:function (data,item) {
      if (data.length<50)
        {return "obj3describe 字数需要超50";}
    },
    obj1pro:function (data,item) {
      var n=data.length;
      if (n<50) {
        return "obj1pro 字数需要超50";
      }
    },
    obj2pro:function (data,item) {
      if (data.length<50)
          {return "obj2pro 字数需要超50";}
    },
    obj3pro:function (data,item) {
      if (data.length<50)
        {return "obj3pro";}
    },
    
    obj1method:function (data,item) {
      if (data.length<50)
        {return "obj1method 字数需要超50";}
    },
    obj2method:function (data,item) {
      if (data.length<100)
        {return "obj2method 字数需要超100";}
    },
    obj3method:function (data,item) {
      if (data.length<50)
        {return "obj3method 字数需要超50";}
    } 
      });
 form.on('submit(div5submit)', function(data){
      layer.msg(JSON.stringify(data.field));
      jQuery.ajax({
                type:"POST",
                contentType:"application/json;charset=UTF-8",
                url:"{$baseurl}/index.php/index/index/settargetanalysis",
                data:JSON.stringify(data.field),
                beforeSend:function(){
                  layer.msg('正在联系服务器......');
                },
                success:function (result) {
                  var x=JSON.parse(result);
                  if (x.result==1) {
                    setstatustoright(5);
                    layer.msg(x.info);
                  }
                }
              });
  return false;
 });
       //表单赋值
      layui.$('#div5resetval').on('click', function(){
        setstatustoing(5);
        form.val('analysisinfo', {
          "obj1pro": "{$obj1pro}",
          "obj1method":"{$obj1method}",
          "obj2pro":"{$obj2pro}",
          "obj2method":"{$obj2method}",
          "obj3pro":"{$obj3pro}",
          "obj3method":"{$obj3method}"
        });
      });
  });




  function drawObjByAjax() { 
    layui.use('layer',function() {
      var layer=layui.layer;

      jQuery.ajax({
        type:"POST",
        contentType:"application/json;charset=UTF-8",
        url:"{$baseurl}/index.php/index/index/getdrawdata", 
        success:function (result) {
          var x=JSON.parse(result);
          console.log(x);
          draw_obj($('#obj1diagcontainer'),'目标1学生成绩达成情况','目标1达成分析',x.data.obj1data,x.data.xlabel);
          draw_obj($('#obj2diagcontainer'),'目标2学生成绩达成情况','目标2达成分析',x.data.obj2data,x.data.xlabel);
          draw_obj($('#obj3diagcontainer'),'目标3学生成绩达成情况','目标3达成分析',x.data.obj3data,x.data.xlabel);
          draw_avg_obj($('#avgdiagcontainer'),'学生成绩总分情况','目标总分分布',x.data.totaldata,x.data.xlabel);
          layer.msg('数据分析成图');

        }
      });
    });
  }

function draw_obj(containerdiv,objtitle,objsubtitle,series,xdata) {
  console.log(series);
    var chart = {
      type: 'scatter'
   };
   var title = {
      text: objtitle   
   };
   var subtitle = {
      text: objsubtitle
   };
   var xAxis = {
      categories: xdata,
      crosshair: true
   };
   var yAxis = {
      min: 0,
      title: {
         text: '学生目标分数'         
      }      
   };
   var tooltip = {
      headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
      pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
         '<td style="padding:0"><b>{point.y:3.2f}</b></td></tr>',
      footerFormat: '</table>',
      shared: true,
      useHTML: true
   };
   var plotOptions = {
      column: {
         pointPadding: 0.2,
         borderWidth: 0
      }
   };  
   var credits = {
      enabled: false
   };
   
   var json = {};   
   json.chart = chart; 
   json.title = title;   
   json.subtitle = subtitle; 
   json.tooltip = tooltip;
   json.xAxis = xAxis;
   json.yAxis = yAxis;  
   json.series = [series];
   json.plotOptions = plotOptions;  
   json.credits = credits;
   containerdiv.highcharts(json);
  }

  function draw_avg_obj(containerdiv,objtitle,objsubtitle,series,xlabel) {
    var chart = {
      type: 'scatter'
   };
   var title = {
      text: objtitle   
   };
   var subtitle = {
      text: objsubtitle
   };
   var xAxis = {
      categories:xlabel,
      crosshair: true
   };
   var yAxis = {
      min: 0,max:100,
      title: {
         text: '总分'         
      }      
   };
   var tooltip = {
      headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
      pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
         '<td style="padding:0"><b>{point.y:3.2f} </b></td></tr>',
      footerFormat: '</table>',
      shared: true,
      useHTML: true
   };
   var plotOptions = {
      column: {
         pointPadding: 0.2,
         borderWidth: 0
      }
   };  
   var credits = {
      enabled: false
   };
   
   var json = {};   
   json.chart = chart; 
   json.title = title;   
   json.subtitle = subtitle; 
   json.tooltip = tooltip;
   json.xAxis = xAxis;
   json.yAxis = yAxis;  
   json.series = [series];
   json.plotOptions = plotOptions;  
   json.credits = credits;
   containerdiv.highcharts(json);
  }
</script>














<div id="div6"  style="display: none;">
       <div class="layui-input-block"  style="margin-top: 20px">
        <button type="button" class="layui-btn" onclick="onlygenerate()" id="LAY-component-form-setval">生成excel</button>
        <button type="button" class="layui-btn" style="display: none;" onclick="generateanddownload()">生成并下载</button>
      </div>
      <div id="downloaddiv" style="margin-top: 20px;display: none;">
        已生成XLS分析报告，<a id="downloadaddress" style="color: #F40" href="">点我下载</a>
      </div>
</div>
<script>
  function onlygenerate() {
    if (stepflags[0]=='X'||stepflags[1]=='X'||stepflags[2]=='X'||stepflags[3]=='X'||stepflags[4]=='X') {
      layer.msg('必须完成前面5个步骤才能生成');
      return;
    }
    layer.msg('Generating');
    jQuery.ajax({
        type:"POST",
        contentType:"application/json;charset=UTF-8",
        url:"{$baseurl}/index.php/index/index/generatexls", 
        success:function (result) {
          var x=JSON.parse(result);
          console.log(x); 
          var downloaddiv=document.getElementById('downloaddiv');
          downloaddiv.setAttribute('style','margin-top:20px;display'); 
          var downloadaddress=document.getElementById('downloadaddress');
          downloadaddress.setAttribute('href',"__ROOT__/public/targetxls/"+x.filename);
          downloadaddress.setAttribute('download',x.filename);
          setstatustoright(6);
          layer.msg(x.info);
        }
      });

  }
  function generateanddownload() {
    if (stepflags[0]=='X'||stepflags[1]=='X'||stepflags[2]=='X'||stepflags[3]=='X'||stepflags[4]=='X') {
      layer.msg('必须完成前面5个步骤才能生成');
      return;
    }
    layer.msg('generateanddownload');
  }
  
</script>




</div>
</div>
<div class="layui-footer">
 卷面数据分析应用程序 Copyright © 2020 Math HZNU. All rights reserved.
</div>
</div>
<script>


// layui.use('table', function(){
//  var table = layui.table;
//   			//监听单元格编辑
//   			table.on('edit(scoredata)', function(obj){
//     		var value = obj.value //得到修改后的值
//     			,data = obj.data //得到所在行所有键值
//     			,field = obj.field; //得到字段
//           layer.msg('[ID: '+ data.id +'] ' + field + ' 字段更改为：'+ value);
//         });
//       });
	










</script>
</body>
</html>